//package com.xiaocikuai.smallchunks.controller.Product;
//
//
//import com.xiaocikuai.smallchunks.entity.Product.LinkCustom;
//import com.xiaocikuai.smallchunks.entity.User.Duser;
//import com.xiaocikuai.smallchunks.service.Product.impl.LinkCustomServiceImpl;
//import com.xiaocikuai.smallchunks.service.User.impl.DuserServiceImpl;
//import com.xiaocikuai.smallchunks.utils.resultd.Resultd;
//import jakarta.annotation.Resource;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * <p>
// * 外部链接获取 前端控制器
// * </p>
// *
// * @author author1
// * @since 2024-07-18
// */
//@RestController
//@RequestMapping("/api/linkcustom")
//public class LinkCustomController {
//    @Resource
//    private LinkCustomServiceImpl linkCustomService;
//
//    @PostMapping("/add")
//    public Resultd add(@RequestHeader("Authorization") String token, @RequestBody LinkCustom linkCustom) {
//        if ( linkCustomService.save(linkCustom)) {
//            return Resultd.ok().data("info", "添加成功");
//        } else {
//            return Resultd.error().data("info", "注册失败");
//        }
//    }
//
//
//    @PostMapping("/delete")
//    public Resultd deleteByID(@RequestHeader("Authorization") String token, @RequestBody LinkCustom linkCustom) {
//        if (linkCustomService.removeById(linkCustom.getId())) {
//            return Resultd.ok().data("info", "删除成功");
//        } else {
//            return Resultd.error().data("info", "删除失败");
//        }
//    }
//
//    @PostMapping("/update")
//    public Resultd updateDuser(@RequestHeader("Authorization") String token, @RequestBody LinkCustom linkCustom) {
//        if (linkCustomService.updateById(linkCustom)) {
//            return Resultd.ok().data("info", "更新成功");
//        } else {
//            return Resultd.error().data("info", "更新失败");
//        }
//    }
//
//    @PostMapping("/select")
//    public Resultd selectDuserList(@RequestHeader("Authorization") String token, @RequestBody LinkCustom linkCustom) {
//        List<LinkCustom> LinkCustoms = linkCustomService.list();
//        if (LinkCustoms!= null) {
//            return Resultd.ok().data("info", LinkCustoms);
//        } else {
//            return Resultd.error().data("info", "未找到对应记录");
//        }
//    }
//
//    @PostMapping("/selectGroup")
//    public Resultd selectGroup(@RequestHeader("Authorization") String token) {
//        List<List<LinkCustom>> result = linkCustomService.selectGroup();
//        if (result != null) {
//            return Resultd.ok().data("info", result);
//        } else {
//            return Resultd.error().data("info", "未找到对应记录");
//        }
//    }
//
//
//
//
//
//
//
//}
package com.xiaocikuai.smallchunks.controller.Product;

import com.xiaocikuai.smallchunks.entity.Product.LinkCustom;
import com.xiaocikuai.smallchunks.entity.User.Duser;
import com.xiaocikuai.smallchunks.service.Product.impl.LinkCustomServiceImpl;
import com.xiaocikuai.smallchunks.service.User.impl.DuserServiceImpl;
import com.xiaocikuai.smallchunks.utils.resultd.Resultd;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 外部链接获取 前端控制器
 * </p>
 *
 * @author author1
 * @since 2024-07-18
 */
@Api(tags = "自定义链接管理控制器")
@RestController
@RequestMapping("/api/linkcustom")
public class LinkCustomController {

    @Resource
    private LinkCustomServiceImpl linkCustomService;

    @ApiOperation(value = "添加自定义链接")
    @PostMapping("/add")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "linkCustom", value = "自定义链接信息", required = true, dataType = "LinkCustom", paramType = "body")
    })
    public Resultd add(@RequestHeader("Authorization") String token, @RequestBody LinkCustom linkCustom) {
        if (linkCustomService.save(linkCustom)) {
            return Resultd.ok().data("info", "添加成功");
        } else {
            return Resultd.error().data("info", "注册失败");
        }
    }

    @ApiOperation(value = "根据 ID 删除自定义链接")
    @PostMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "linkCustom", value = "自定义链接信息（包含 ID）", required = true, dataType = "LinkCustom", paramType = "body")
    })
    public Resultd deleteByID(@RequestHeader("Authorization") String token, @RequestBody LinkCustom linkCustom) {
        if (linkCustomService.removeById(linkCustom.getId())) {
            return Resultd.ok().data("info", "删除成功");
        } else {
            return Resultd.error().data("info", "删除失败");
        }
    }

    @ApiOperation(value = "更新自定义链接")
    @PostMapping("/update")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "linkCustom", value = "自定义链接信息", required = true, dataType = "LinkCustom", paramType = "body")
    })
    public Resultd updateDuser(@RequestHeader("Authorization") String token, @RequestBody LinkCustom linkCustom) {
        if (linkCustomService.updateById(linkCustom)) {
            return Resultd.ok().data("info", "更新成功");
        } else {
            return Resultd.error().data("info", "更新失败");
        }
    }

    @ApiOperation(value = "查询自定义链接列表")
    @PostMapping("/select")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "linkCustom", value = "自定义链接信息（用于筛选）", required = true, dataType = "LinkCustom", paramType = "body")
    })
    public Resultd selectDuserList(@RequestHeader("Authorization") String token, @RequestBody LinkCustom linkCustom) {
        List<LinkCustom> LinkCustoms = linkCustomService.list();
        if (LinkCustoms!= null) {
            return Resultd.ok().data("info", LinkCustoms);
        } else {
            return Resultd.error().data("info", "未找到对应记录");
        }
    }

    @ApiOperation(value = "分组查询自定义链接")
    @PostMapping("/selectGroup")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header")
    })
    public Resultd selectGroup(@RequestHeader("Authorization") String token) {
        List<List<LinkCustom>> result = linkCustomService.selectGroup();
        if (result!= null) {
            return Resultd.ok().data("info", result);
        } else {
            return Resultd.error().data("info", "未找到对应记录");
        }
    }
}
